package com.mao.swagger.controller;

import com.mao.swagger.entity.User;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

/**
 * @author 小毛同学
 * @version 1.0
 * @data 2022/1/2 12:08
 */

@Api(tags = "说明该类的作用")
@RestController
public class HelloController {

    @ApiOperation(value = "说明方法的用途，作用",notes = "方法的备注说明")
    @GetMapping("/hello")
    public String hello(){
        return "hello";
    }

    @PostMapping("/search")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "姓名",required = true,paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "age",value = "年龄",required = true,paramType = "query",dataType = "Integer"),
    })
    @ApiOperation("测试查询")
    public String search(String name,Integer age){
        return name+""+age;
    }

    @PostMapping("/add")
    @ApiOperation("测试添加")
    public String add(User user){
        return user.getUsername()+" " + user.getAge();
    }

    @GetMapping("/user/{id}")
    @ApiOperation("根据用户id获取返回数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "用户编号",required = true,paramType = "path")
    })
    @ApiResponses({
            @ApiResponse(code=408,message = "指定业务得报错信息，返回客户端"),
            @ApiResponse(code=404,message = "请求路径不对")
    })
    public User load(@PathVariable("id") Integer id){
        return new User(id,"jack",11);
    }
}


